package mn.slide.labmed;

import mn.slide.labmed.actual.ActualisierenActivity;
import mn.slide.labmed.info.InfoTabGroupActivity;
import mn.slide.labmed.merkliste.MerklisteTabGroupActivity;
import mn.slide.labmed.verluaf.VerluafTabGroupActivity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

public class MainTabActivity extends TabActivity
{
	TabHost.TabSpec	spec;
	/** Called when the activity is first created. */
	TabHost			tabHost;
	boolean			one;

	@Override
	public void onCreate( Bundle savedInstanceState )
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		tabHost = getTabHost();
		setTabs();

	}

	private void setTabs()
	{
		addTab("Home", R.drawable.tab_home, HomeTabGroupActivity.class);
		addTab("Merkliste", R.drawable.tab_merkliste, MerklisteTabGroupActivity.class);
		addTab("Verlauf", R.drawable.tab_verluaf, VerluafTabGroupActivity.class);
		addTab("Aktualisieren", R.drawable.tab_refresh, ActualisierenActivity.class);
		addTab("Info", R.drawable.tab_info, InfoTabGroupActivity.class);
	}

	private void addTab( String labelId , int drawableId , Class<?> c )
	{
		Intent intent = new Intent(this, c);
		spec = tabHost.newTabSpec(labelId);
		View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
		TextView title = (TextView) tabIndicator.findViewById(R.id.title);
		title.setText(labelId);
		ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
		icon.setImageResource(drawableId);

		spec.setIndicator(tabIndicator);
		spec.setContent(intent);
		tabHost.addTab(spec);
		tabHost.setCurrentTab(0);
		tabHost.getTabWidget().getChildAt(0).setOnClickListener(new View.OnClickListener()
		{
			public void onClick( View v )
			{
				tabHost.setCurrentTab(0);
				HomeTabGroupActivity.group.back1();
				Log.d("darlaa", "darlaa");
			}
		});
	}

	@Override
	public void onResume()
	{
		super.onResume();
		tabHost.getTabWidget().getChildAt(0).setOnClickListener(new View.OnClickListener()
		{
			public void onClick( View v )
			{
				tabHost.setCurrentTab(0);
				HomeTabGroupActivity.group.back1();
				Log.d("darlaa", "darlaa");
			}
		});
		tabHost.getTabWidget().getChildAt(1).setOnClickListener(new View.OnClickListener()
		{
			public void onClick( View v )
			{
				tabHost.setCurrentTab(1);
			}
		});
		tabHost.getTabWidget().getChildAt(2).setOnClickListener(new View.OnClickListener()
		{
			public void onClick( View v )
			{
				tabHost.setCurrentTab(2);
			}
		});
		tabHost.getTabWidget().getChildAt(3).setOnClickListener(new View.OnClickListener()
		{
			public void onClick( View v )
			{
				tabHost.setCurrentTab(3);
			}
		});
		tabHost.getTabWidget().getChildAt(4).setOnClickListener(new View.OnClickListener()
		{
			public void onClick( View v )
			{
				tabHost.setCurrentTab(4);
			}
		});
	}

}